package com.tedu.test;

import com.tedu.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
 * Created by IntelliJ IDEA.
 *
 * @author zq
 * @version 1.0
 * @create 2024-07-30 11:27
 * @since jdk1.8
 */
public class JDBCDemo01 {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            //调用工具类，，，获取连接
            conn = JDBCUtils.getConnection();
            //3，获取传输器 ，利用高级的工具类执行SQL
            //先执行SQL骨架
            String sql = "delete from user where id=?";
            ps = conn.prepareStatement(sql);
            //给第一个问号，设置值是1
            ps.setInt(1, 1);
            //4,执行SQL
            int rows = ps.executeUpdate();
            System.out.println("删除成功");
        } catch (Exception e) {
            System.out.println("执行失败...");
        } finally { //最终一定会被执行的
            //5,释放资源

            JDBCUtils.close(null, ps, conn);

        }
    }
}
